package com.zyj.myapplication.Fragment;

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zyj.myapplication.Adapter.CoachListAdapter;
import com.zyj.myapplication.Javabean.Coach;
import com.zyj.myapplication.Model.CoachModel;
import com.zyj.myapplication.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class HomeCoachFragment extends Fragment {
    private RecyclerView recyclerView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.activity_home_coach_fragment,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.coach_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
       showData();
        return view;
    }
    public void showData(){
        CoachModel coachModel = new CoachModel();
        Call<List<Coach>> call = coachModel.getcoachList();
        call.enqueue(new Callback<List<Coach>>() {
            @Override
            public void onResponse(Call<List<Coach>> call, Response<List<Coach>> response) {
                List<Coach> mDataList = response.body();
                LinearLayoutManager manager=new LinearLayoutManager(getActivity());
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(manager);
                recyclerView.setAdapter(new CoachListAdapter(HomeCoachFragment.this.getContext(),mDataList));
            }//b绑定一个适配器

            @Override
            public void onFailure(Call<List<Coach>> call, Throwable t) {

            }
        });
    }

}
